package winOrDie.graphicsInterface.GameRoom;

import java.util.Vector;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

public class Composite_Rols extends Composite {

	private Button button_Select_Rol_Captain = null;
	private Button button_Select_Rol_Maiden = null;
	
private Vector<Composite_Rols_Listener> listeners = null;
	
	public synchronized void add_Composite_Rols_Listener(Composite_Rols_Listener listener)
	{
		listeners.add(listener);
	}
	
	public synchronized void remove_Composite_Rols_Listener(Composite_Rols_Listener listener)
	{
		listeners.remove(listener);
	}
	
	public void fire_Composite_Rols_Event(Composite_Rols_Event event)
	{
		for (Composite_Rols_Listener listener : listeners) {
			listener.on_Composite_Rols_Changed(event);
		}
	}	
	
	public Composite_Rols(Composite parent, int style) 
	{
		super(parent, style);
		listeners = new Vector<Composite_Rols_Listener>();
		initialize();
	}

	private void initialize() 
	{
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 2;
		setLayout(gridLayout);
		
		get_Select_Rol_Maiden();
		get_Select_Rol_Captain();
	}
	
	public Button get_Select_Rol_Captain()
	{
		if (button_Select_Rol_Captain == null)
		{
			GridData gridData = new GridData();
			gridData.horizontalAlignment = SWT.CENTER;
			gridData.verticalAlignment = SWT.CENTER;
			
			button_Select_Rol_Captain = new Button(this, SWT.PUSH);
			button_Select_Rol_Captain.setLayoutData(gridData);
			
			button_Select_Rol_Captain.setText("Capitán");
			
			final Composite_Rols compositeRols = this;			
			
			button_Select_Rol_Captain.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					Composite_Rols_Event event = new Composite_Rols_Event(compositeRols);
					event.setEventType(Composite_Rols_Event.Event_Types.SELECT_CAPTAIN);
					fire_Composite_Rols_Event(event);
				}
			});
		}
		return button_Select_Rol_Captain;
	}
	
	public Button get_Select_Rol_Maiden()
	{
		if (button_Select_Rol_Maiden == null)
		{
			GridData gridData = new GridData();
			gridData.horizontalAlignment = SWT.CENTER;
			gridData.verticalAlignment = SWT.CENTER;
			
			button_Select_Rol_Maiden = new Button(this, SWT.PUSH);
			button_Select_Rol_Maiden.setLayoutData(gridData);
			
			button_Select_Rol_Maiden.setText("Princesa");
			
			final Composite_Rols compositeRols = this;			
			
			button_Select_Rol_Maiden.addSelectionListener(new SelectionAdapter() {
				public void widgetSelected(SelectionEvent e) {
					Composite_Rols_Event event = new Composite_Rols_Event(compositeRols);
					event.setEventType(Composite_Rols_Event.Event_Types.SELECT_MAIDEN);
					fire_Composite_Rols_Event(event);
				}
			});
		}
		return button_Select_Rol_Maiden;
	}
	
}
